
/*
 * Copyright 2008 Friendster Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using Friendster.Service.Core;
using System.Net;

namespace Friendster.Service
{
    /// <summary>
    /// Represents the user info methods of Friendster Platform.
    /// </summary>
    public sealed class FansService
    {
        // Fields
        private string _session;

        // Methods
        /// <summary>
        /// Initializes the session to use the methods.
        /// </summary>
        /// <param name="session"></param>
        internal FansService(string session)
        {
            this._session = session;
        }
        /// <summary>
        /// Get the fans list of a fan profile, specified by userID
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public string[] GetFans(string userID)
        {
            FriendsterRequest request = new FriendsterRequest(this._session);
            if (string.IsNullOrEmpty(userID))
            {
                userID = request.UserID;
            }

            FriendsterResponse response = request.InvokeMethod("GET", "fans/" + userID);
            if (!response.IsError)
            {
                ArrayList _result = (ArrayList)response.Result;
                Hashtable result = (Hashtable)_result[0];
                ArrayList fanslist = new ArrayList();
                fanslist = (ArrayList)result["fans"];
                if (fanslist!=null)
                    return (string[])fanslist.ToArray(typeof(string));
            }
            return null;
        }
        /// <summary>
        /// Get the fans list of a fan profile of current user (if any).
        /// </summary>
        /// <returns></returns>
        public string[] GetFans()
        {
            return GetFans(null);
        }
    }
}